package com.hisense.proxy.busitrans.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hisense.proxy.service.entity.output_invoice.InvoiceBuildParam;
import com.hisense.proxy.service.utils.HttpClientUtil;
import com.hisense.proxy.service.utils.URLConfigEnum;

@RestController
@RequestMapping("query")
public class HxFdcprBusitransQueryStatusProxyController {

	
	@PostMapping("/blue")
	public JSONObject queryBlueInvoice(@RequestBody JSONObject reqParams) throws Exception {
		String fpqqlsh = reqParams.getString("fpqqlsh");
		Map<String, String> paramsMap = InvoiceBuildParam.buildQueryInvoiceStatusPostParam(fpqqlsh);
        String result = HttpClientUtil.post(URLConfigEnum.QUERY_INBOICE_STATUS.getUrl(), (Map) paramsMap);
        JSONObject resultObj = JSON.parseObject(result);
        
        return resultObj;
	}
	
	
	@PostMapping("/red")
	public JSONObject qeuryRedInvoice(@RequestBody JSONObject reqParams) throws Exception {
        return queryBlueInvoice(reqParams);
	}
	
	@GetMapping("/zdybz")
	public String qeuryZdybzInvoice(@RequestParam String fpqqlsh, @RequestParam String method) throws Exception {
		if ("get".equals(method)) {
			return InvoiceBuildParam.zdybzMap.get(fpqqlsh);
		} 
		InvoiceBuildParam.zdybzMap.remove(fpqqlsh);
		
		return "ok";
		
	}
	
	
	
}
